from django.db import models
from django.template import Library
from core.tree.models import Tree

register = Library()

@register.inclusion_tag("admin/tree/tree/change_list_results.html")
def core_result_list(cl):
    tree = Tree.objects.all()
    results = tree
    
    #for item in tree:
        #if item.level == 0:
           # results.append(buildTree(item, tree))
    
    return {'cl': cl,
            'nodes': results}
    
def buildTree(array, tree):
    result = []
    for item in tree:
        if item.parent_id == array.id:
            result.append(buildTree(item, tree))
        else:
            result.append(array)
    return result